package com.zggk.lzz.roadz;

import android.app.Activity;
import com.alibaba.fastjson.JSON;
import com.zggk.lzz.api.MyApplication;
import com.zggk.lzz.api.Urls;
import com.zggk.lzz.callback.StringDialogCallback;
import com.zggk.lzz.mvp.BasePresenterImpl;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

/**
 * MVPPlugin
 *  邮箱 784787081@qq.com
 */

public class RoadZPresenter extends BasePresenterImpl<RoadZContract.View> implements RoadZContract.Presenter{
    @Override
    public void getOne(String orgCode, Activity activity) {
        OkGo.<String>post(Urls.JAVASERVER+"pms/rhms/lzzapp/findStatistical")
                .params("orgId", orgCode)
                .params("token", "Bearer$" + MyApplication.spUtils.getString("Token",""))
                .execute(new StringDialogCallback(activity) {
                    @Override
                    public void onSuccess(Response<String> response) {
                        RoadZoneInfo roadZoneInfo = JSON.parseObject(response.body(),RoadZoneInfo.class);
                        if (mView == null)
                            return;
                        if (roadZoneInfo.getCode().equals("200")){
                            mView.getOnes(roadZoneInfo.getData());
                        }else {
                            mView.onRequestError(roadZoneInfo.getMessage());
                        }
                    }
                });
    }
    @Override
    public void getTwo() {
        OkGo.<String>post(Urls.JAVASERVER+"pms/rhms/lzzapp/ourWork")
                .params("token", "Bearer$" + MyApplication.spUtils.getString("Token",""))
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        RoadZtwoInfo roadZtwoInfo = JSON.parseObject(response.body(),RoadZtwoInfo.class);
                        if (mView == null)
                            return;
                        if (roadZtwoInfo.getCode().equals("200")){
                            mView.getTwos(roadZtwoInfo.getData());
                        }else {
                            mView.onRequestError(roadZtwoInfo.getMessage());
                        }
                    }
                });
    }
    @Override
    public void getThree() {
        OkGo.<String>post(Urls.JAVASERVER+"pms/rhms/lzzapp/report")
                .params("token", "Bearer$" + MyApplication.spUtils.getString("Token",""))
                .params("pageIndex", "0")
                .params("pageSize", "4")
                .params("sortOrder", "desc")
                .params("sortField", "findtime")
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        RoadZthreeInfo roadZthreeInfo = JSON.parseObject(response.body(),RoadZthreeInfo.class);
                        mView.getThrees(roadZthreeInfo);
                    }
                });
    }
}
